import React from 'react';
import ReactDom from 'react-dom';
import './pickup.scss';
import Button from 'views/component/button/button';
import { api } from 'js/api/api';
import playerStore from 'js/store/playerStore';
//较少,少量,大量,丰富,充足,充裕,较多,稍许,少许,一般


let handleText = {
    1: '拾取', 2: '采集', 3: '采矿', 4: '采伐', 5: '钓鱼', 6: '调查'
};


class Pickup extends React.Component {
    constructor() {
        super()
        this.state = {

        }
    }
    componentDidMount() {

    }
    pickUp = (itemId) => {
        api('homePickUp', { buildingId: parseInt(this.props.buildingId), itemId: parseInt(itemId) }, (err, data) => {
            if (data.log) {
                window.eventHandle.emit('log', data.log);
            }
            this.setState({})
            if (this.props.complete) {
                this.props.complete()
            }
        });
    }
    render() {
        let { buildingId } = this.props;
        let propName = window.propName;
        let totalConfig = window.totalConfig;
        let buildingConfig = totalConfig.building;
        let buildingConfigInfo = buildingConfig[buildingId];
        let itemId = buildingConfigInfo.itemId;
        let player = playerStore.player;
        let mapId = player.basicInfo.mapId;
        let homeInfo = player.homeInfo;
        let buildInfo = homeInfo.building[buildingId];
        let itemNode = [];
        for (let itemId in buildInfo.item) {
            itemNode.push(<div className="pickup-item flex-vcenter" key={itemId}>
                <div className="name flex-col-4">{propName[itemId]}</div>
                <div className="amount flex-col-4">{buildInfo.item[itemId]}</div>
                <div className="flex-col-4">
                    <Button onClick={() => { this.pickUp(itemId) }}>{handleText[buildingConfigInfo.buildingType]}</Button>
                </div>
            </div>)
        }
        return <div id="pickup" className="flex-col">
            <div className="header">{propName[buildingId]}</div>
            <div className="pickup-content flex-g-1 flex-col">
                <div className="pickup-desc">
                    {buildingConfigInfo.desc}
                </div>
                <div className="flex-g-1 flex-col-vcenter">
                    {itemNode}
                </div>
            </div>
            <div className="pickup-bottom flex">
                <div className="flex-g-1" onClick={this.props.close}>返回</div>
            </div>
        </div>
    }
}

export default Pickup;